





//
//  CustomeScrollView.m
//  U9WatchGame
//
//  Created by uuu9 on 15/11/10.
//  Copyright © 2015年 Jason. All rights reserved.
//

#import "CustomeScrollView.h"
#import "CustomLabel.h"
@implementation CustomeScrollView

-(instancetype)init
{
    if (self = [super init]) {
        self.backgroundColor = [UIColor colorWithRed:238/255.0 green:238/255.0 blue:238/255.0 alpha:1.0];
        self.normalBackImage = nil;
        self.selectedBackImage = nil;
        self.normalFont = [UIFont systemFontOfSize:15.0];
        self.selectedFont = [UIFont systemFontOfSize:15.0];
        self.normalForegroundColor = [UIColor whiteColor];
        self.selectedForegroundColor = [UIColor whiteColor];
    }
    return self;
}


- (void)setThemesArray:(NSMutableArray *)themesArray
{
    for (UIView *view in self.subviews) {
        if ([view isKindOfClass:[UIButton class]]) {
            [view removeFromSuperview];
        }
    }
    __block float lastWidth = 11;
    for (int i = 0; i < themesArray.count; i++) {
        UIButton *btn = [[UIButton alloc] init];
        [btn setBackgroundImage:self.normalBackImage forState:UIControlStateNormal];
        [btn setBackgroundImage:self.selectedBackImage forState:UIControlStateSelected];
        NSAttributedString *attrNormal = [[NSAttributedString alloc] initWithString:themesArray[i] attributes:@{NSFontAttributeName:self.normalFont, NSForegroundColorAttributeName:self.normalForegroundColor}];
        [btn setAttributedTitle:attrNormal forState:UIControlStateNormal];
        NSAttributedString *attrSelected = [[NSAttributedString alloc] initWithString:themesArray[i] attributes:@{NSFontAttributeName:self.selectedFont, NSForegroundColorAttributeName:self.selectedForegroundColor}];
        [btn setAttributedTitle:attrSelected forState:UIControlStateSelected];
        CGSize size = attrNormal.size;
        btn.frame = CGRectMake(lastWidth, 6, size.width + 16, 26);
        [btn addTarget:self action:@selector(clickTheme:) forControlEvents:UIControlEventTouchUpInside];
        lastWidth += ceilf(btn.frame.size.width) + 10;
        btn.tag = i;
        [self addSubview:btn];
        btn.layer.cornerRadius = 13;
        btn.layer.masksToBounds = YES;
        if (i == 0) {
            btn.selected = YES;
        }
    }
    self.contentSize = CGSizeMake(lastWidth, 36);
}



- (void)clickTheme:(UIButton *)sender
{
    for (UIView *view in self.subviews) {
        if ([view isKindOfClass:[UIButton class]]) {
            ((UIButton *)view).selected = NO;
        }
    }
    sender.selected = YES;
    _ClickThemeBlock(sender.titleLabel.text);
    
    
}



@end
